package com.ruoyi.intelligence.chat.aliyun;

import cn.hutool.json.JSON;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesis;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisListResult;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisParam;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.utils.JsonUtils;
import io.swagger.v3.core.util.Json;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @Author: wxj
 * 通义万象
 * @Date: 2023/11/23
 */
@Component
@Slf4j
public class TywxFactory {

    public List<Map<String, String>> basicCall(String msg, Integer num, String size) throws ApiException, NoApiKeyException {
        ImageSynthesis is = new ImageSynthesis();
        ImageSynthesisParam param =
            ImageSynthesisParam.builder()
                .model(ImageSynthesis.Models.WANX_V1)
                .apiKey("sk-010ca67d2a35422cba1f0fe9d214dd96")
                //期望生成的图片数量,目前限制最多生成4张
                .n(num>4?4:3)
                //生成的图片的规格 默认1024*1024
                .size(size)
                .prompt(msg)
                .build();

        ImageSynthesisResult result = is.call(param);
        log.info("打印通义万象的返回结果：{}", JsonUtils.toJsonString(result));
        List<Map<String, String>> results = result.getOutput().getResults();
        return results;
    }



}
